package com.ews.onlineexchange.service;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.approved.ApprovedClass;
import com.ews.onlineexchange.model.approved.ApprovedMatter;
import com.ews.onlineexchange.model.approved.ApprovedType;
import com.ews.onlineexchange.model.approved.ViolationRecord;

@Model
public class ViolationRecordList extends EntityQuery<ViolationRecord> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ViolationRecordList() {
		setOrder("createDate DESC");
	}

	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<ViolationRecord> entity) {		
		List<Predicate> restrictions = super.getRestrictions(cb, entity);
		
		Join<ApprovedMatter, ApprovedClass> clazz = entity.join("approvedMatter").join("approvedClass");		
		restrictions.add(cb.equal(clazz.get("approvedType"), ApprovedType.Violation));
		
		return restrictions;
	}

}
